import java.sql.*;
import java.io.*;

public
class TableOsoba
{
	public String IMIE = "";
	public String NAZWISKO = "";
	public String ADRES = "";
	public String TELEFON = "";
	public String EMAIL = "";

	public TableOsoba()
	{
	}
	public boolean readFromStream(BufferedReader inp)
	{
		String line = null;
		try{
			line = inp.readLine();
		}
		catch(IOException e){
			DatabaseTest.outp.println("Bd przy odczycie: " + e);
			return false;
		}
		if (line == null){
			return false;
		}
		return parseLine(line);
	}
	public boolean parseLine(String line)
	{
		IMIE = "";
		NAZWISKO = "";
		ADRES = "";
		TELEFON = "";
		EMAIL = "";

		String s;
		int pos;
		if ((pos = line.indexOf(';')) < 0){
			return false;
		}
		s = line.substring(0, pos);
		IMIE = s.trim();
		line = line.substring(pos + 1, line.length());

		if ((pos = line.indexOf(';')) < 0){
			return false;
		}
		s = line.substring(0, pos);
		NAZWISKO = s.trim();
		line = line.substring(pos + 1, line.length());

		if ((pos = line.indexOf(';')) < 0){
			return true;
		}
		s = line.substring(0, pos);
		ADRES = s.trim();
		line = line.substring(pos + 1, line.length());

		if ((pos = line.indexOf(';')) < 0){
			return true;
		}
		s = line.substring(0, pos);
		TELEFON = s.trim();
		line = line.substring(pos + 1, line.length());

		if ((pos = line.indexOf(';')) < 0){
			return true;
		}
		s = line.substring(0, pos);
		EMAIL = s.trim();
		line = line.substring(pos + 1, line.length());

		return true;
	}
	public void insert(Connection conn)
	throws SQLException
	{
		String query = "INSERT INTO OSOBA";
		query += "(IMIE, NAZWISKO, ADRES, TELEFON, EMAIL )";
		query += " VALUES (";
		query += "'" + IMIE + "','" + NAZWISKO + "','" + ADRES + "','";
		query += TELEFON + "','" + EMAIL + "')";
		
		Statement statement = conn.createStatement();
		statement.executeUpdate(query);
		statement.close();
	}
	public String toString()
	{
	return (IMIE + ", " + NAZWISKO +  ", " + ADRES + ", " + TELEFON + ", " + EMAIL + ";");
	}
}
